package com.fenqing.leetcode.code.t700_800;

import com.fenqing.annotations.DesignClass;
import com.fenqing.core.design.DesignTopic;

import java.util.LinkedList;
import java.util.List;

/**
 * @author fenqing
 */
public class Topic705 extends DesignTopic {

    public Topic705() {
        super("[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]"
                , "[[], [1], [2], [1], [3], [2], [2], [2], [2]]");
    }

    public static void main(String[] args) {
        Topic705 topic705 = new Topic705();
        System.out.println(topic705.run());
    }

    @DesignClass
    public static class MyHashSet {

        List<Integer>[] hash = new List[100000];

        public MyHashSet() {

        }

        public void add(int key) {
            int index = key % hash.length;
            if (hash[index] == null) {
                hash[index] = new LinkedList<>();
            }
            if (!hash[index].contains(key)) {
                hash[index].add(key);
            }
        }

        public void remove(int key) {
            int index = key % hash.length;
            if (hash[index] == null) {
                return;
            }
            hash[index].remove((Object) key);
        }

        public boolean contains(int key) {
            int index = key % hash.length;
            if (hash[index] == null) {
                return false;
            }
            return hash[index].contains(key);
        }
    }

}
